/**
 * Class Style
 * this class is used to create css rules
 */
Style = (function () {

    /**
     * Style constructor
     * @constructor
     */
    function Style() {
        this.styles = document.styleSheets;
		this.style = this.styles[this.styles.length-1];
	}
    /**
     * Create rule string form object and selector
     * @param selector {String} CSS selector
     * @param rule {Object} css rules
     * @returns {string} string rule
     */
	Style.prototype.createRule = function(selector, rule){
		return selector+" "+JSON.stringify(rule).replace(/["']/g, " ").replace(/,/g, ";");
	};
    /**
     * Add rule in to style
     * @param selector {String} CSS selector
     * @param rule {Object} css rules
     * @returns {Number} index of rule
     */
	Style.prototype.addRule = function(selector, rule){
        return this.style.insertRule(this.createRule(selector, rule), this.style.cssRules.length);
    };
    /**
     * Get rule by index
     * @param index {Number} rule index
     * @returns {CssRule|CSSRule}
     */
	Style.prototype.getRule = function(index){
		return this.style.cssRules[index];
	};
    /**
     * Edit rule by index
     * @param index {Number} index of edited rule
     * @param rule {Object} new css rule
     */
	Style.prototype.editRule = function(index, rule){
		var cssSelector = this.getRule(index).selectorText;
		this.style.removeRule(index);
		this.style.insertRule(this.createRule(cssSelector, rule), index);
	};
    /**
     * Remove Css rule
     * @param index {Number} rule index
     * @returns {*|void}
     */
	Style.prototype.removeRule = function(index){
		return this.style.removeRule(index);
	};

    return Style;

})();